<!DOCTYPE html>
<html lang="zh_CN">
<head>
    <#assign currentMenu="product"/>
    <#include "../common/header.ftl">
    <script src="/js/plugins/jquery-bootstrap/jquery.bootstrap.min.js"></script>

    <style type="text/css">
        .modal-body {
            max-height: 750px;
            overflow-y: auto;
        }
        .modal-body img {
            width: 100%;
        }
    </style>

    <script>
        $(function () {
            //点击查看内容按钮弹出模态框
            $(".contentBtn").click(function () {
                //获取当前商品的id
                var id = $(this).data("tid");

                //发送请求查询当前商品信息
                $.get("/product/get.do",{id:id},function (data) {
                    $("#contentModal .modal-body").html(data.content);
                });


                $("#contentModal").modal("show");

            });

            //初始化CKeditor
            var edt = CKEDITOR.replace("ckeditor");

            // 点击设为推荐按钮弹出模态框
            $(".inputBtn").click(function () {

                // 先清空数据
                $("#editForm input").val("");

                $("#coverUrl").attr("src", "");

                // 获得json数据
                var json = $(this).data("json");

                if (json) {
                    // 回显数据 id，name,price,coverUrl
                    console.log(json);
                    $("#editForm input[name='id']").val(json.id);
                    $("#editForm input[name='name']").val(json.name);
                    $("#editForm input[name='price']").val(json.price);
                    $("#editForm input[name='coverUrl']").val(json.coverUrl);
                    $("#editForm select[name='state']").val(json.state);
                    $("#coverUrl").attr("src",json.coverUrl);
                    edt.setData(json.content);
                }

                // 显示出模态框
                $("#inputModal").modal("show");

            });

            // 模态框提交
            $(".submitBtn").click(function () {
                // 把ckeditor的数据填充到文本中，再提交表单
                $("#ckeditor").html(edt.getData());
                $("#editForm").submit();
            });


            // 发布和拒绝
            $(".changeStateBtn").click(function () {
                var json = $(this).data("json");

                $.messager.confirm("温馨提示","确定当前操作吗?",function () {
                    // 发送ajax请求,执行更新状态
                    $.post("/product/changeState.do",json,function (data) {
                        location.reload();
                    });
                });
            });
        })
    </script>
</head>
<body>

<div class="container " style="margin-top: 20px">
    <#include "../common/top.ftl">
    <div class="row">
        <div class="col-lg-2">
            <#include "../common/menu.ftl">
        </div>
        <div class="col-lg-10">
            <div class="row">
                <div class="col-lg-12">
                    <h1 class="page-head-line">商品管理</h1>
                </div>
            </div>
            <!--高级查询--->
            <form class="form-inline" id="searchForm" action="/product/list.do" method="post">
                <input type="hidden" name="currentPage" id="currentPage" value="1">
                <div class="form-group">
                    <label>关键字:</label>
                    <input type="text" class="form-control" name="keyword" value="${(qo.keyword)!}"
                           placeholder="请输入商品名称">
                </div>
                <div class="form-group">
                    <label>状态:</label>
                    <select class="form-control" name="state">
                        <option value="-1">全部</option>
                        <option value="0">未上架</option>
                        <option value="1">已上架</option>
                    </select>

                    <script type="text/javascript">
                        $("#searchForm select[name='state']").val(${qo.state});
                    </script>

                </div>

                <button id="btn_query" class="btn btn-default btn-success">
                    <span class="glyphicon glyphicon-search"></span> 查询
                </button>
                <a role="button" class="btn btn-default btn-info inputBtn">
                    <span class="glyphicon glyphicon-plus"></span> 新增
                </a>
            </form>

            <table class="table table-striped table-hover">
                <tr>
                    <th>序号</th>
                    <th>封面</th>
                    <th>名称</th>
                    <th>价格</th>
                    <th>状态</th>
                    <th>操作</th>
                </tr>
                <#list pageInfo.list as entity>
                    <tr>
                        <td>${entity_index + 1}</td>
                        <td><img src="${entity.coverUrl}" width="100"/></td>
                        <td style="width: 450px">${entity.name}</td>
                        <td>${entity.price}</td>
                        <td>${entity.stateName}</td>
                        <td>
                            <a role="button" class="btn btn-primary btn-sm inputBtn" data-json='${entity.json}'>
                                <span class="glyphicon glyphicon-pencil"></span> 修改
                            </a>
                            <a href="javascript:" class="btn btn-danger btn-sm changeStateBtn" data-json='{"id":${entity.id}, "state": 0}'>
                                <span class="glyphicon glyphicon-ok"></span> 下架
                            </a>
                            <a href="javascript:" class="btn btn-primary btn-sm contentBtn"  data-tid="${entity.id}">
                                <span class="glyphicon glyphicon-sunglasses"></span> 查看内容
                            </a>
                        </td>
                    </tr>
                </#list>
            </table>
            <#include "../common/page.ftl">
        </div>
    </div>
</div>

<div id="contentModal" class="modal" tabindex="-1" role="dialog">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title">商品内容</h4>
            </div>
            <div class="modal-body">
            </div>
            <div class="modal-footer">
                <a role="button" class="btn btn-info" data-dismiss="modal" aria-hidden="true">关闭</a>
            </div>
        </div>
    </div>
</div>

<#--设为推荐模态框-->
<div id="inputModal" class="modal" tabindex="-1" role="dialog">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
                <h4 class="modal-title">商品信息</h4>
            </div>
            <div class="modal-body">
                <form class="form-horizontal" action="/product/saveOrUpdate.do" method="post"
                      enctype="multipart/form-data" id="editForm">
                    <input type="hidden" name="id"/>
                    <div class="form-group" >
                        <label class="col-lg-4 control-label">商品名称：</label>
                        <div class="col-lg-6">
                            <input type="text" class="form-control" name="name"/>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-lg-4 control-label">积分价格：</label>
                        <div class="col-lg-6">
                            <input type="text" class="form-control" name="price"/>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-lg-4 control-label">商品图片：</label>
                        <div class="col-lg-6">
                            <img id="coverUrl" style="width: 100%"/>
                            <input type="file" class="form-control" name="img"/>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-lg-4 control-label">是否上架：</label>
                        <div class="col-lg-6">
                            <select class="form-control" name="state">
                                <option value="0">未上架</option>
                                <option value="1">已上架</option>
                            </select>
                        </div>
                    </div>
                    <div class="form-group">
                        <textarea name="content" id="ckeditor"></textarea>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                <button type="button" class="btn btn-primary submitBtn">保存</button>
            </div>
        </div>
    </div>
</div>
<script src="/js/plugins/ckeditor/ckeditor.js"></script>


<script type="text/javascript">
    
</script>
</body>
</html>